home *** CD-ROM | disk | FTP | other *** search
/ MacHack 2000 / MacHack 2000.toast / pc / The Hacks / MacHacksBug / Python 1.5.2c1 / Extensions / Imaging / Scripts / pilfile.py < prev    next >
Encoding:
Python Source  |  2000-06-23  |  1.7 KB  |  77 lines

  1. #! /usr/local/bin/python
  2. #
  3. # The Python Imaging Library.
  4. # $Id: pilfile.py,v 1.1.1.1 1998/08/18 13:07:59 sjoerd Exp $
  5. #
  6. # a utility to identify image files
  7. #
  8. # this script identifies image files, extracting size and
  9. # pixel mode information for known file formats.  Note that
  10. # you don't need the PIL C extension to use this module.
  11. #
  12. # History:
  13. # 0.0    95-09-01 fl    Created
  14. # 0.1    96-05-18 fl    Modified options, added debugging mode
  15. # 0.2    96-12-29 fl    Added verify mode
  16. #
  17.  
  18. import Image
  19.  
  20. import getopt, sys
  21.  
  22. if len(sys.argv) == 1:
  23.     print "PIL File 0.2/96-12-29 -- identify image files"
  24.     print "Usage: pilfile [option] files..."
  25.     print "Options:"
  26.     print "  -f  list supported file formats"
  27.     print "  -i  show associated info and tile data"
  28.     print "  -v  verify file headers"
  29.     print "  -q  quiet, don't warn for unidentified/missing/broken files"
  30.     sys.exit(1)
  31.  
  32. try:
  33.     opt, argv = getopt.getopt(sys.argv[1:], "fqivD")
  34. except getopt.error, v:
  35.     print v
  36.     sys.exit(1)
  37.  
  38. verbose = quiet = verify = 0
  39.  
  40. for o, a in opt:
  41.     if o == "-f":
  42.         Image.init()
  43.     id = Image.ID[:]
  44.     id.sort()
  45.     print "Supported formats:"
  46.     for i in id:
  47.         print i, 
  48.     sys.exit(1)
  49.     elif o == "-i":
  50.         verbose = 1
  51.     elif o == "-q":
  52.         quiet = 1
  53.     elif o == "-v":
  54.         verify = 1
  55.     elif o == "-D":
  56.         Image.DEBUG = Image.DEBUG + 1
  57.  
  58. for file in argv:
  59.     try:
  60.     im = Image.open(file)
  61.     print "%s:" % file, im.format, "%dx%d" % im.size, im.mode,
  62.     if verbose:
  63.         print im.info, im.tile,
  64.     print
  65.     if verify:
  66.         try:
  67.         im.verify()
  68.         except:
  69.         if not quiet:
  70.             print "failed to verify image",
  71.             print "(%s:%s)" % (sys.exc_type, sys.exc_value)
  72.     except IOError, v:
  73.     if len(v) == 2:
  74.         x, v = v
  75.     if not quiet:
  76.         print file, "failed:", v
  77.